<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "xd_task_type".
 *
 * @property string $id
 * @property string $name
 * @property integer $is_fixed
 * @property integer $status
 * @property string $create_time
 * @property string $update_time
 */
class TaskType extends \yii\db\ActiveRecord
{
    const STATUS_INACTIVE = 0;
    const STATUS_ACTIVE   = 1;
    const STATUS_DELETED  = 2;
    
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'xd_task_type';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['is_fixed', 'status'], 'integer'],
            [['create_time', 'update_time'], 'safe'],
            [['name'], 'string', 'max' => 100],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', '主键id'),
            'name' => Yii::t('app', '类型名'),
            'is_fixed' => Yii::t('app', '是否固定任务 0不是，1是，默认0'),
            'status' => Yii::t('app', '任务状态'),
            'create_time' => Yii::t('app', '创建时间'),
            'update_time' => Yii::t('app', '修改时间'),
        ];
    }
    
    /**
     * 获取所有类型
     * 
     * @return array
     */
    public static function getAllTaskType()
    {
        $model = self::find();
        $model->andWhere( [ 'status' => self::STATUS_ACTIVE ] );
        $model->orderBy('is_fixed desc');
        $res = $model->asArray()->all();
        return $res;
    }
    
    public function getTypeLists($is_fixed = 0){
        $typeArr = TaskType::find()
                ->select('id,name')
                ->where('status=:status and is_fixed =:is_fixed', [':status' => TaskType::STATUS_ACTIVE, ':is_fixed' => $is_fixed])
                ->asArray()->all();
        return $typeArr;
    }
}
